/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package VIEW;

import CONTROL.Khoa_Control;
import CONTROL.SinhVien_Control;
import MODEL.khoa;
import MODEL.sinhvien;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
//import javax.swing.text.Element;

import javax.xml.parsers.DocumentBuilderFactory;
import sun.swing.table.DefaultTableCellHeaderRenderer;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Element;
import MODEL.sinhvien;
import java.io.File;

      

/**
 *
 * @author CONGTHANH
 */
public class frmSinhVien extends javax.swing.JFrame {
   String dialogtitle="Xác nhận";
    String message = "Bạn có chắc muốn thoát?";
     private Date ngaysinh;
    /**
     * tao  form frmSinhVien
     */
  private  DefaultTableModel tb;
    private DefaultComboBoxModel cb;
    public frmSinhVien() {
         initComponents();
        tb=new DefaultTableModel();
       // tb.addColumn("STT");
        tb.addColumn("Mã Sinh Viên");
        tb.addColumn("Họ Tên Sinh Viên");
        tb.addColumn("Ngày Sinh");
        tb.addColumn("Địa Chỉ");
        tb.addColumn("Điện Thoại");
        tb.addColumn("Email");
        tb.addColumn("Tên Khoa");
        load();
        tblsv.setModel(tb);
        tblsv.getColumnModel().getColumn(0).setPreferredWidth(100);  
        tblsv.getColumnModel().getColumn(1).setPreferredWidth(250);
        tblsv.getColumnModel().getColumn(2).setPreferredWidth(250);
        tblsv.getColumnModel().getColumn(3).setPreferredWidth(300);
        tblsv.getColumnModel().getColumn(4).setPreferredWidth(382);
        tblsv.getColumnModel().getColumn(5).setPreferredWidth(182);
        tblsv.getColumnModel().getColumn(6).setPreferredWidth(382);
       // tblsv.getColumnModel().getColumn(7).setPreferredWidth(382);
        //tblsv.getColumnModel().getColumn(6).setPreferredWidth(182);
       
        DefaultTableCellRenderer r=new DefaultTableCellHeaderRenderer();
        r.setHorizontalAlignment(jLabel1.CENTER);
        tblsv.getColumnModel().getColumn(0).setCellRenderer(r);  
        tblsv.getColumnModel().getColumn(1).setCellRenderer(r);
        tblsv.getColumnModel().getColumn(2).setCellRenderer(r);
        tblsv.getColumnModel().getColumn(3).setCellRenderer(r);
        tblsv.getColumnModel().getColumn(4).setCellRenderer(r);
        tblsv.getColumnModel().getColumn(5).setCellRenderer(r);
        tblsv.getColumnModel().getColumn(6).setCellRenderer(r);
       // tblsv.getColumnModel().getColumn(7).setCellRenderer(r);
        cb=new DefaultComboBoxModel();
        loadkh();
        cmbmk.setModel(cb);
      
        
    }
    
    public void loadkh(){
        ArrayList<khoa> kq=Khoa_Control.tenkhoacmb();
        for(khoa k: kq){
            cb.addElement(k);
        }
    }

     public void load(){
        ArrayList<sinhvien> kq=SinhVien_Control.layTATCASV();
      //  int stt=1;
        for(sinhvien l: kq){
            Vector v=new Vector();
          //  v.add(stt);
            v.add(l.getMasv());
            v.add(l.getTensv());
            v.add(l.getNgaysinh());
            v.add(l.getDiachi());
            v.add(l.getDienthoai());
            v.add(l.getEmail());
            
         String s= l.getMakhoa();
        // mak="select * from khoa,sinhvien where khoa.makhoa=sinhvien.makhoa";// MaKHoa="+l.getMakhoa();
          //  LoaiKhachHang kh=LoaiKhachHangDAO.tenloaikh(mak);
          khoa kh=Khoa_Control.tenkh(s);
          //  kh.tenkh();
                  
            v.add(kh.getTenkhoa());
            
            tb.addRow(v);
         //   stt++;
        }
        
    }
    
    private static ArrayList<sinhvien> dssv = new ArrayList<sinhvien>();
        

    public ArrayList<sinhvien> getDSSV() {
        return dssv;
    }
 public void gandulieu(sinhvien sv){
      
                sv.masv = txtmasv.getText();
                sv.Tensv = txttensv.getText();
                sv.ngaysinh = txtns.getText();
                sv.diachi = txtdc.getText();
                sv.Dienthoai = txtdt.getText();
                sv.email = txtem.getText();
               
                sv.makhoa=((khoa)cmbmk.getSelectedItem()).getMakhoa();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txttensv = new javax.swing.JTextField();
        txtdt = new javax.swing.JTextField();
        txtem = new javax.swing.JTextField();
        txtns = new javax.swing.JTextField();
        txtdc = new javax.swing.JTextField();
        txtmasv = new javax.swing.JTextField();
        btnthemsv = new javax.swing.JButton();
        btnxoasv = new javax.swing.JButton();
        btnsuasv = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        tbnthoat = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblsv = new javax.swing.JTable();
        cmbmk = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        bntloadcd = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("nam sinh ");

        jLabel2.setText("dia chi");

        jLabel3.setText("ten sinh vien");

        jLabel4.setText("ma sinh vien");

        jLabel5.setText("email");

        jLabel6.setText("dien thoai");

        jLabel7.setText("ten khoa");

        txttensv.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txttensvKeyPressed(evt);
            }
        });

        txtmasv.setEditable(false);
        txtmasv.setBackground(new java.awt.Color(102, 102, 102));
        txtmasv.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        txtmasv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtmasvActionPerformed(evt);
            }
        });

        btnthemsv.setText("them");
        btnthemsv.setToolTipText("");
        btnthemsv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnthemsvActionPerformed(evt);
            }
        });

        btnxoasv.setText("xoa");
        btnxoasv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnxoasvActionPerformed(evt);
            }
        });

        btnsuasv.setText("sua");
        btnsuasv.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnsuasvActionPerformed(evt);
            }
        });

        jButton4.setText("Màn Hình Chính");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        tbnthoat.setText("Thoat");
        tbnthoat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tbnthoatActionPerformed(evt);
            }
        });

        tblsv.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblsv.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblsvMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblsv);

        cmbmk.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel8.setBackground(new java.awt.Color(102, 255, 0));
        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(0, 0, 255));
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel8.setText("Quản Lý\n Thông Tin\n Sinh Viên"); // NOI18N

        bntloadcd.setText("LoadCD");
        bntloadcd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntloadcdActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txttensv, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtns, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtdc, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(135, 135, 135)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel5)
                            .addComponent(jLabel6))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtem, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbmk, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtdt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19))
            .addGroup(layout.createSequentialGroup()
                .addGap(165, 165, 165)
                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(38, 38, 38)
                .addComponent(jButton4)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(43, 43, 43)
                .addComponent(btnthemsv, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(71, 71, 71)
                .addComponent(btnxoasv, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(80, 80, 80)
                .addComponent(btnsuasv, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 79, Short.MAX_VALUE)
                .addComponent(tbnthoat, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(21, 21, 21))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtmasv, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(203, 203, 203))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(bntloadcd)
                        .addGap(32, 32, 32))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txttensv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(23, 23, 23)
                                        .addComponent(jLabel1))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txtns, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(30, 30, 30)
                                        .addComponent(jLabel2))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel7)
                                                .addComponent(cmbmk, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(txtdc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(txtem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(5, 5, 5))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(7, 7, 7)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtmasv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 27, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(txtdt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5)
                        .addGap(55, 55, 55)))
                .addComponent(bntloadcd)
                .addGap(33, 33, 33)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(tbnthoat, javax.swing.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
                    .addComponent(btnxoasv, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(btnthemsv, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnsuasv, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(8, 8, 8))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
           Main f=new Main();
        f.setVisible(true);
        this.dispose();
         
    }//GEN-LAST:event_jButton4ActionPerformed
   /* public void Load_DS_SV() throws SQLException
    {
        DefaultTableModel model = (DefaultTableModel)tblsv.getModel();
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        SinhVien_Control csv = new SinhVien_Control();
        for(sinhvien sv : csv.getDSSV())
        {
            Vector Row = new Vector();
            Row.addElement(sv.getMasv());
            Row.addElement(sv.getTensv());
            Row.addElement(sv.getNgaysinh());
            Row.addElement(sv.getDiachi());
            Row.addElement(sv.getDienthoai());
            Row.addElement(sv.getEmail());
            Row.addElement(sv.getMakhoa());
                               
            model.addRow(Row);
            
            
        }
        tblsv.setModel(model);
        
        
    }*/
    public int NgayHople(String Chuoi)
	{
            
		try
		{
			DateFormat df=DateFormat.getDateInstance (DateFormat.SHORT);
			df.setLenient (false);
			ngaysinh=df.parse (Chuoi);
			if(this.ngaysinh.getYear()>11)
				return 1;
                        else 
				return -1;
		}
		catch(ParseException e)
		{
			return 0;
		}
	}
       public int tuoiHopLe(String chuoi)
	{
	Date hienhanh=new Date();
    	int ngay=hienhanh.getDate ();
    	int thang=hienhanh.getMonth ()+1;
    	int nam=hienhanh.getYear ()+2000;

	StringTokenizer token;
	Vector vtam=new Vector();

	token=new StringTokenizer(chuoi,"/");
	while(token.hasMoreTokens())
	{
            vtam.addElement (token.nextToken ());
	}
	int cngay=Integer.parseInt (vtam.elementAt (0).toString ());
	int cthang=Integer.parseInt (vtam.elementAt (1).toString ());
	int cnam=Integer.parseInt (vtam.elementAt (2).toString ());

	int Hople=nam-cnam;
	if(Hople>18)
		return 1;
	return-1;

	}
   
    private void btnthemsvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnthemsvActionPerformed
        // TODO add your handling code here:
        
       if(!txttensv.getText().trim().equals("") &&!txtns.getText().trim().equals("")&&!txtdc.getText().trim().equals("")&&!txtdt.getText().trim().equals("")&&!txtem.getText().trim().equals(""))
       {
            String dt=txtdt.getText();
          
            for(int i=0;i<dt.length();i++){
                if(!Character.isDigit(dt.charAt(i))){
                    JOptionPane.showMessageDialog(this, "Điện Thoại Phải Là Số");
                    txtdt.requestFocus();
                    return ;
                }
             
                else if (dt.length()<10||dt.length()>11){
                
                JOptionPane.showMessageDialog(this, "Điện Thoại Phải từ 10-11 so");
                txtdt.requestFocus();
                    return;
                }
            }
            
           //  String sql="insert into khachhang(MaKH,HoTenKH,DiaChi,DienThoai,MaLoaiKH) values("+ma+",'"+jtxtht.getText().trim()+"','"+jtxtdc.getText()+"',"+Integer.parseInt(jtxtdt.getText()) +","+((LoaiKhachHang)jcmblkh.getSelectedItem()).getmaloai()+")";
          try{
              JOptionPane msg=new JOptionPane();
           
             if(!txtns.getText().trim().equals(""))
            {
                sinhvien sv = new sinhvien();
		//int Hople=this.NgayHople (this.txtns.getText());
		
                   //  if(txtns.g)
		//if(Hople==0)
		//{
			//JOptionPane.showMessageDialog(null,"Ban da nhap sai dinh dang ngay. Xin ban nhap lai Ngay sinh!(Chu y ngay phai dung dang sau yy/mm/dd)");
			//this.txtns.requestFocus ();
			//this.txtns.selectAll ();
		//}
		/*else if(Hople==-1)
		{
			JOptionPane.showMessageDialog(null,"Ban da nhap nam sai(nam chi tinh tu 1990). Xin ban nhap lai nam sinh");
			this.txtns.requestFocus ();
			this.txtns.selectAll ();
		}*/
		//else if(Hople==1)
		//{
			int tuoiHopLe=this.tuoiHopLe(txtns.getText());
                        if(tuoiHopLe==-1)
                            msg.showMessageDialog(null,"Ngay thang chua hop le vi nguoi nay chua du tuoi di hoc");
                       // else
                        //{
                       SinhVien_Control svc=new SinhVien_Control();
                       sv.masv=svc.tutangma();
                        // sv.masv = txtmasv.getText();
                             sv.Tensv = txttensv.getText();
                            sv.ngaysinh = txtns.getText();
                            sv.diachi = txtdc.getText();
                             sv.Dienthoai = txtdt.getText();
                                sv.email = txtem.getText();
               
                                 sv.makhoa=((khoa)cmbmk.getSelectedItem()).getMakhoa();
                       
                            
             
                    SinhVien_Control tsv = new  SinhVien_Control();
                       tsv.Them(sv);
                        //JOptionPane.showMessageDialog(this, "Thêm Thành Công");
                        txtdc.setText("");
                         txtdt.setText("");
                         txttensv.setText("");
                         txtmasv.setText("");
                         txtem.setText("");
                         txtns.setText("");
                         while(tblsv.getRowCount()>0)
                              tb.removeRow(0);
                           load();
                       // }
						
                //}
            
            }
              
           }catch(Exception ex){
            //JOptionPane.showMessageDialog(this, "Them that bai");
               JOptionPane.showMessageDialog(null, ex);
           }
            
        }else
            JOptionPane.showMessageDialog(this, "Bạn Phải Nhập Đầy Đủ Thông Tin");
                      
    }//GEN-LAST:event_btnthemsvActionPerformed

    private void tbnthoatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbnthoatActionPerformed
        // TODO add your handling code here:
         int x = JOptionPane.showConfirmDialog(this, message, dialogtitle, JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE);
    if (x == JOptionPane.YES_OPTION) 
    {
        System.exit(0);
    }
    }//GEN-LAST:event_tbnthoatActionPerformed
public void lammoi(){

               txtdc.setText("");
               txtdt.setText("");
               txttensv.setText("");
               txtmasv.setText("");
               txtem.setText("");
              // txtmk.setText("");
               txtns.setText("");

}
    private void btnxoasvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnxoasvActionPerformed
        // TODO add your handling code here:
            int kk=0;
       //  if(tblsv.getSelectedRow() < 0)
       // {
            
         //   JOptionPane.showMessageDialog(rootPane,"Bạn chưa chọn dòng nào để xoá !");
           // return;
       // }
       // TODO add your handling code here:
        if(!txtmasv.getText().trim().equals(""))
        {
            // int i=tblsv.getSelectedRow();
            
            sinhvien sv=new sinhvien();
              //sv.masv=tb.getValueAt(i, 0).toString();
            sv.masv=txtmasv.getText();
            try{
            SinhVien_Control n=new SinhVien_Control();
              //  String sql="delete from sinhvien where MASV='"+txtmasv.getText()+"'";
     //n=SinhVien_Control.(sv);
                n.Xoa(sv);
                
                kk++;
            }catch(Exception ex){}
               // String sql="delete from khachhang where MaKH="+txtmasv.getText();
                //int kq=SinhVien_Control.xoatheoma(sv);
                if(kk>0){
                    JOptionPane.showMessageDialog(this, "Xóa Thành Công");
                    txtdc.setText("");
                     txtdt.setText("");
                     txttensv.setText("");
                     txtmasv.setText("");
                     txtem.setText("");
                    txtns.setText("");
                   while(tblsv.getRowCount()>0) 
                   tb.removeRow(0);
                  load();
                }
            }
        else
        JOptionPane.showMessageDialog(this, "Bạn Phải Nhập Đầy Đủ Thông Tin");
                                           
                
        
    }//GEN-LAST:event_btnxoasvActionPerformed

    private void txttensvKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txttensvKeyPressed
        // TODO add your handling code here:
         // String sql="select * from khachhang where HoTenKH like '"+jtxtht.getText()+"%'";
        /*  sinhvien sv=new sinhvien();
          sv.Tensv=txttensv.getText();
        ArrayList<sinhvien> kq=SinhVien_Control.timkiemtheoten(sv);
        
        while(tb.getRowCount()>0)
            tb.removeRow(0);
        for(sinhvien k: kq){
            Vector v=new Vector();
            v.add(k.getMasv());
            v.add(k.getTensv());
            v.add(k.getNgaysinh());
            v.add(k.getDiachi());
            v.add(k.getDienthoai());
            v.add(k.getEmail());
            v.add(k.getMakhoa());
            
            //
           // sql="select * from loaikhachhang where MaLoaiKH="+k.getMlkh();
              khoa kh=Khoa_Control.tenkh();
          //  kh.tenkh();
                  
            v.add(kh.getTenkhoa());
            
            tb.addRow(v);
           // LoaiKhachHang kh=LoaiKhachHangDAO.tenloaikh(sql);
             
            //v.add(kh.gettenloai());
            //load();
            
            tb.addRow(v);
            
        }*/
        
    }//GEN-LAST:event_txttensvKeyPressed

    private void tblsvMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblsvMouseClicked
        // TODO add your handling code here:
        int i=tblsv.getSelectedRow();
        txtmasv.setText(tb.getValueAt(i, 0).toString());
        txttensv.setText(tb.getValueAt(i, 1).toString());
         txtns.setText(tb.getValueAt(i, 2).toString());
        txtdc.setText(tb.getValueAt(i, 3).toString());
         txtdt.setText(tb.getValueAt(i, 4).toString());
       txtem.setText(tb.getValueAt(i, 5).toString());
        
        for(int j=0;j<cb.getSize();j++){
            if(((khoa)cmbmk.getItemAt(j)).getTenkhoa().equals(tb.getValueAt(i, 6).toString())){
                cmbmk.setSelectedIndex(j);
                break;
            }
        }
       
    }//GEN-LAST:event_tblsvMouseClicked

    private void txtmasvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtmasvActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtmasvActionPerformed

    private void btnsuasvActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsuasvActionPerformed
        // TODO add your handling code here:
          // TODO add your handling code here:
        
        if(!txtmasv.getText().trim().equals("") ){
                sinhvien sv = new sinhvien();
               
                             sv.masv = txtmasv.getText(); 
                             sv.Tensv = txttensv.getText();
                            sv.ngaysinh = txtns.getText();
                            sv.diachi = txtdc.getText();
                             sv.Dienthoai = txtdt.getText();
                                sv.email = txtem.getText();
               
                                 sv.makhoa=((khoa)cmbmk.getSelectedItem()).getMakhoa();
             
             String dt=txtdt.getText();
            
            for(int i=0;i<dt.length();i++)
                if(!Character.isDigit(dt.charAt(i)))
                {
                    JOptionPane.showMessageDialog(this, "Điện Thoại Phải Là Số");
                    return;
                }
              //  masv='"+txtmasv.getText().trim()+"'
               // String ma=((sinhvien)cmbmk.getSelectedItem()).getMakhoa();
               // String ma=txtmasv.getText();
               
                // String sql="update sinhvien set tensv='"+txttensv.getText()+"',namsinh='"+txtns.getText()+"',DiaChi='"+txtdc.getText()+"',Dienthoai="+Integer.parseInt(txtdt.getText()) +",email='"+txtem.getText()+"',Makhoa='"+((khoa)cmbmk.getSelectedItem()).getMakhoa()+"' where Masv='"+txtmasv.getText()+"'";
                int kq=SinhVien_Control.suasv(sv);
                if(kq>0){
                    JOptionPane.showMessageDialog(this, "Sữa Thành Công");
                    txtdc.setText("");
                    txtdt.setText("");
                    txtmasv.setText("");
                    txttensv.setText("");
                    txtem.setText("");
                    txtns.setText("");
                    while(tblsv.getRowCount()>0)
                    tb.removeRow(0);
                    
                    load();
                }
            
        }else
        JOptionPane.showMessageDialog(this, "Bạn Phải Chọn Thông Tin");
        
    }//GEN-LAST:event_btnsuasvActionPerformed
public void loadstudent(){
   // public static final String INPUT_FILE = "C:\\dataInput.xml";
    
     
            
    try{
        
        
       // private Vector<sinhvien> sv= new Vector<sinhvien>();
        File  file=new File("C:\\NHAPCD.XML");
        DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
        DocumentBuilder db=dbf.newDocumentBuilder();
        Document doc=db.parse(file);
        getdata(doc);
        
    }
     catch(Exception ex){ex.printStackTrace();}
}
Vector vt=new Vector();

public Vector<sinhvien> getsinhvien()
{ return vt;}

private void getdata(Node node){
sinhvien sv=new sinhvien();;

if(node ==null){
    return;}
if(node.getNodeName().equals("masv")){
    
    sv.setMasv(node.getTextContent());
    vt.add(sv.getMasv());
    
}
if(node.getNodeName().equals("tensv")){
sv.setTensv(node.getTextContent());
vt.add(sv.getTensv());
}
if(node.getNodeName().equals("namsinh")){
   sv.setNgaysinh(node.getTextContent());
   vt.add(sv.getNgaysinh());
}
if(node.getNodeName().equals("diachi")){
sv.setDiachi(node.getTextContent());

}
if(node.getNodeName().equals("dienthoai")){
sv.setDienthoai(node.getTextContent());

}
if(node.getNodeName().equals("email")){
sv.setEmail(node.getTextContent());

}
if(node.getNodeName().equals("makhoasv")){
sv.setMakhoa(node.getTextContent());
//vt.add(sv);
}
//NodeList children =node.getChildNodes();

     // for (int index = 0; index < children.getLength(); index++) {
           // getdata(children.item(index));
       // }
                            sv.Tensv = txttensv.getText();
                          //  sv.ngaysinh = txtns.getText();
                           // sv.diachi = txtdc.getText();
                            // sv.Dienthoai = txtdt.getText();
                              //  sv.email = txtem.getText();
                              // vt.add(sv.getMasv());
                              //  vt.add(sv.getTensv());
                               // vt.add(sv.getNgaysinh());
                               // vt.add(sv.getDiachi());
                               // vt.add(sv.getDienthoai());
                              //  vt.add(sv.getEmail());
                               // vt.add(sv.getMakhoa());
                                vt.add(sv);
                                tb.addRow(vt);
                                
   
}
public static final String in="C:\\NHAPCD.XML";
private static String gettagvalue(String Stag,Element eElement){
    NodeList nlist = eElement.getElementsByTagName(Stag).item(0).getChildNodes();
    Node nvalue =(Node)nlist.item(0);
    return nvalue.getNodeValue();
}


    private void bntloadcdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntloadcdActionPerformed
        // TODO add your handling code here:
        
        loadstudent();
       // load();
      // sinhvien sv=new sinhvien();
       
       
    }//GEN-LAST:event_bntloadcdActionPerformed
 //ArrayList<sinhvien> dssinhvien = new ArrayList<sinhvien>();
  //  public ArrayList<sinhvien> getsinhvien() {
     //  return dssinhvien;
  //  }
    /**
     * @param args the command line arguments
     */
   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bntloadcd;
    private javax.swing.JButton btnsuasv;
    private javax.swing.JButton btnthemsv;
    private javax.swing.JButton btnxoasv;
    private javax.swing.JComboBox cmbmk;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTable tblsv;
    private javax.swing.JButton tbnthoat;
    private javax.swing.JTextField txtdc;
    private javax.swing.JTextField txtdt;
    private javax.swing.JTextField txtem;
    private javax.swing.JTextField txtmasv;
    private javax.swing.JTextField txtns;
    private javax.swing.JTextField txttensv;
    // End of variables declaration//GEN-END:variables
}
